package com.stox.client.ui.javafx.workbench.view;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.Region;

import com.stox.client.ui.javafx.core.util.CSS;
import com.stox.client.ui.javafx.core.util.UI;
import com.stox.shared.core.i18n.MessageSource;

public class TitleBar extends ToolBar{
	private final Button closeButton = UI.mediumCrossButton(MessageSource.get("Close"));
	private final Button settingsButton = UI.mediumGearButton(MessageSource.get("Configure"));
	private final HBox right = new HBox(settingsButton, closeButton);
	private final Label title = new Label();
	private final HBox left = new HBox(title);
	private final Region spacer = new Region();
	private final View view;
	
	public TitleBar(final View view) {
		this.view = view;
		UI.style(this, CSS.titleBar);
		UI.style(title, CSS.viewTitleBarTitle);
		UI.style(left, CSS.viewTitleLeft);
		
		closeButton.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>(){
			@Override
			public void handle(ActionEvent event) {
				view.close();
			}
		});
		
		settingsButton.addEventHandler(ActionEvent.ACTION, new EventHandler<ActionEvent>(){
			@Override
			public void handle(ActionEvent event) {
				view.configure();
			}
		});
		
		HBox.setHgrow(spacer, Priority.ALWAYS);
		getItems().addAll(left, spacer, right);
	}

	public void setTitleText(String titleText){
		title.setText(titleText);
	}
	
	public View getView() {
		return view;
	}
	
	public HBox getLeft() {
		return left;
	}
	
	public HBox getRight() {
		return right;
	}
	
	public Button getSettingsButton() {
		return settingsButton;
	}
	
	public Button getCloseButton() {
		return closeButton;
	}
}
